草庐IT

php - 简单的preg_replace

全部标签

encryption - 从 PHP 到 Go 的 Mcrypt

我在PHP中使用一个类来加密/解密字符串。我如何在Go中加密/解密字符串?PHP类:classCrypto{private$encryptKey='xxxxxxxxxxxxxxxx';private$iv='xxxxxxxxxxxxxxxx';private$blocksize=16;publicfunctiondecrypt($data){return$this->unpad(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$this->encryptKey,hex2bin($data),MCRYPT_MODE_CBC,$this->iv),$this->blo

php - 长时间运行的 Golang 程序和资源(文件句柄、tcp 连接等)

我有PHP背景,我对如何安全地使用Golang资源感到有点困惑。我主要担心的是,在web上下文中,使用PHP,脚本通常是短暂的(HTTP请求/响应生命周期),但使用Golang,它们应该永远运行(因为Golang程序充当Web服务器和Web同时申请)。所以,在处理数据库连接、日志文件时,我经常看到应该打开一次,而不是每个请求都打开,这是有道理的。然而,这样做有多稳定?例如,如果我打开一个数据库连接,我如何确定它不会在某个时候中断?(如果数据库出于某种原因决定终止它,或者如果我的机器失去互联网访问权限,那么当我稍后获得互联网访问权限时,连接会再次有效吗?)对于日志文件也是如此,对于PHP

http - Go 中的简单 HTTP POST 文件上传

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭4年前。Improvethisquestion我只需要知道在Go中使用HTTPPOST将文件发送到远程服务器的极其简单的方法。我已经尝试了很多复杂的方法但没有运气。我的curl命令是这样的:curlhttps://api.example.com/upload\--userapi:YOUR_API_K

php - 如何在 golang 中读取 pkcs12 内容,我在 PHP 中有示例

有解密和签名接口(interface)。我想从PHP迁移到Golang。PHP函数如下:functiongetSignature($param){if(is_string($param)){$file_private='file.p12';if(!$cert_store=file_get_contents($file_private)){return"Error:Unabletoreadthecertfile\n";}$signature="";$algo="sha256WithRSAEncryption";$password="PASSWORD";$private_key_file=

go - 从 time.Now() 开始接收字符串的简单方法

我正在尝试从time.Now()实例中获取日期作为字符串。now:=time.Now()//.String()wouldgivemetheentiredateasastringwhichIdon'tneedday:=now.Day())//iswhatIwantbutasaString.所以string(day)告诉我“无法将day转换为string”。现在对我来说.Day().String()会很好但是没有这样的方法...我现在可以尝试使用time.Now().String()并进行操作,直到一天结束。但应该有更简单的方法来做到这一点...... 最佳答案

php - Golang 和 Phpass (Php) 怎么办?

我在一家公司工作,我必须将他们的API从Php重新制作到Golang。以前的开发人员在Php中使用Phpass,但是,我需要在Golang中使用它。我搜索了如何在go中实现phpass,但它似乎不如在php中有效。我看到了这些github实现:gopass—在go中实现phpass算法phpass—PHPass密码的go实现...也许这很奇怪,但是它在Php中的工作原理是一样的吗?对我来说,每次我使用相同的密码/使用得到一个新的散列密码。我也从来没有用过php,所以我真的不知道如何测试这个类/库(phpass)感谢帮助! 最佳答案

终端上的golang简单静态服务器打印

这是我最初的golang代码:packagemainimport("net/http""io")consthello=`helloworld`funchelloHandler(whttp.ResponseWriter,r*http.Request){io.WriteString(w,hello)}funcmain(){http.HandleFunc("/",helloHandler)http.ListenAndServe(":1088",nil)}这是一个简单的http服务器,我需要添加新的功能,在linux终端ip、METHOD、/request中打印每个get请求。终端需要的示例输

http - 运行一个简单的服务器,但计数器似乎增加了 3,为什么?

这个问题在这里已经有了答案:Whythissimplewebserveriscalledevennumbertimes?(1个回答)关闭6年前。我这里有这个小服务器。目的是如果我访问localhost:8000/*它应该将counter加1,如果我访问localhost:8000/count,它应该显示counter。发生的一件奇怪的事情是,似乎每次我访问localhost:8000时,计数器都会增加3。所以我会转到localhost:8000/count和counter将在3,然后我访问localhost:8000,然后再次访问localhost:8000/count,counter

arrays - 这个使用范围的简单 For 循环如何以及为什么在 Go 中打印一个简单的 3D 数组?

我尝试以这种方式使用range函数来打印电路板并且它确实有效,但我无法解决为什么?行数、列数如何计算?packagemainimport"fmt"funcmain(){varboard[2][2][2]stringforrow:=rangeboard{forcolumn:=rangeboard{forthird:=rangeboard{fmt.Print(row,column,third)fmt.Println()}}}} 最佳答案 您的代码并没有按照您的想法行事。您在每个循环中迭代顶级数组。每个数组恰好有2个元素这一事实给了你成功

Golang 泛型 - 简单用例

假设我有3个结构:typeAstruct{Foomap[string]string}typeBstruct{Foomap[string]string}typeCstruct{Foomap[string]string}然后我想创建一个可以接受任何这些结构的函数:funchandleFoo(){}有什么方法可以用Golang做到这一点吗?像这样的东西:typeABC=A|B|CfunchandleFoo(vABC){x:=v.Foo["barbie"]//thiswouldbenice!}好的,让我们尝试一个接口(interface):typeFMLinterface{Bar()strin